import React from 'react';
import { Form, Button } from 'antd';
import { CompanyDepartPlus } from '@/containers';
import { SearchInput } from '@/components/UserForm';
import { getemployeelist } from '@/services/attendance/overtime';

const SearchForm = ({ form, onSearch, onChange, user, code, fetchListData, ...rest }) => {
    const { getFieldDecorator } = form;
    const [companyId, setCompanyId] = React.useState();

    const handleSubmit = e => {
        e.preventDefault();
        onSearch();
    };

    const change = v => {
        form.resetFields(['employeeIds']);
        onChange(v.companyId);
        setCompanyId(v.companyId);
    };

    return (
        <Form layout="inline" onSubmit={handleSubmit} {...rest}>
            <Form.Item label="机构">
                {getFieldDecorator('companyDepart')(
                    <CompanyDepartPlus
                        hideOrg
                        onChange={v => {
                            change(v);
                        }}
                    />
                )}
            </Form.Item>
            <Form.Item label="员工：">
                {getFieldDecorator(
                    'employeeIds',
                    {}
                )(
                    <SearchInput
                        requireParam={['administrativeOrganizationCode']}
                        params={{
                            administrativeOrganizationCode: companyId
                        }}
                        getData={_params =>
                            getemployeelist(_params).then(res => {
                                if (res && res.code === 10000) {
                                    return res.data || [];
                                }
                                return [];
                            })
                        }
                        fieldsName={{
                            value: 'employeeCode',
                            title: 'employeeName',
                            extraParams: 'userName'
                        }}
                        selectProps={{
                            placeholder: '请选择',
                            mode: 'multiple',
                            maxTagCount: 3,
                            style: { width: '200px' }
                        }}
                    />
                )}
            </Form.Item>
            <Form.Item>
                <Button type="primary" htmlType="submit">
                    搜索
                </Button>
            </Form.Item>
        </Form>
    );
};
export default SearchForm;
